<script lang="ts">
export default {
  name: 'GoodsInfo'
}
</script>
<script lang="ts" setup>
import GoodsSalesVue from './components/goods-sales.vue'
import GoodsNameVue from './components/goods-name.vue'
import GoodsSkuVue from './components/goods-sku.vue'
import useStore from '@/store'
import goodsImageVue from './components/goods-image.vue';
import { onUnmounted, watchEffect } from 'vue'
import { useRoute } from 'vue-router'
const { goods } =useStore()
const route = useRoute()
const stop = watchEffect(() => {
  //得到 id 参数
  const id = route.params.id as string
  goods.getInfo(id)
}, {
  flush: 'post'
})
onUnmounted(() => {
  stop()
})
</script>
<template>
  <div class="xtx-goods-page" v-if="goods.info.categories">
    <div class="container">
      <!-- 面包屑 -->
      <XtxBread>
        <XtxBreadItem to="/">首页</XtxBreadItem>
        <XtxBreadItem to="/">{{ goods.info.categories[1].name }}</XtxBreadItem>
        <XtxBreadItem to="/">{{ goods.info.categories[0].name }}</XtxBreadItem>
        <XtxBreadItem to="/">{{ goods.info.name }}</XtxBreadItem>
      </XtxBread>
      <!-- 商品信息 -->
      <div class="goods-info">
        <!-- 左 -->
        <div class="media">
          <!-- 放大镜 -->
          <goodsImageVue :images="goods.info.mainPictures"></goodsImageVue>
        <!-- 销量 -->
        <GoodsSalesVue></GoodsSalesVue>
        </div>
        <!-- 右 -->
        <div class="spec">
          <GoodsNameVue :goods="goods.info"></GoodsNameVue>
          <!-- 规格组件 -->
          <GoodsSkuVue :goods="goods.info"></GoodsSkuVue>
        </div>
      </div>
      <!-- 商品详情 -->
      <div class="goods-footer">
        <div class="goods-article">
          <!-- 商品+评价 -->
          <div class="goods-tabs"></div>
        </div>
        <!-- 24热榜+专题推荐 -->
        <div class="goods-aside"></div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="less">
.goods-info {
  min-height: 600px;
  background: #fff;
  display: flex;

  .media {
    width: 580px;
    height: 600px;
    padding: 30px 50px;
  }

  .spec {
    flex: 1;
    padding: 30px 30px 30px 0;
  }
}

.goods-footer {
  display: flex;
  margin-top: 20px;

  .goods-article {
    width: 940px;
    margin-right: 20px;
  }

  .goods-aside {
    width: 280px;
    min-height: 1000px;
  }
}

.goods-tabs {
  min-height: 600px;
  background: #fff;
}

.goods-warn {
  min-height: 600px;
  background: #fff;
  margin-top: 20px;
}
</style>